﻿using DicomViewerAdvanced.VirtualMouse;
using KinectWindows.Math;
using KinectWindows.Nui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace KinectWindows.Controls
{
    public class NuiControl : FrameworkElement, INuiable
    {

        private ControlStateFlag CurrentState;
        public void SetBounds(Vector4 rect)
        {
            Canvas.SetLeft(this, rect.Left);
            Canvas.SetLeft(this, rect.Right);
            Canvas.SetRight(this, rect.Top);
            Canvas.SetTop(this, rect.Buttom);
        }
        public Vector4 GetBounds()
        {
            Vector4 bounds = new Vector4();
            bounds.Left=(float)Canvas.GetLeft(this);
            bounds.Buttom =(float) Canvas.GetBottom(this);
            bounds.Right=(float)Canvas.GetRight(this);
            bounds.Top=(float)Canvas.GetTop(this);
            return bounds;


        }

        #region events

        #endregion
        #region for internal use
        internal void LeftHandHitTest(mouseImposter point)
        {

            if (GetBounds().TestPoint(point.Location)) CurrentState = ControlStateFlag.INSIDE;
            else CurrentState = ControlStateFlag.OUTSIDE;
            DoLefthandControl();
        }
        // Test hand position relative to control
        internal void RightHandHitTest(mouseImposter point)
        {
            if (GetBounds().TestPoint(point.Location)) CurrentState = ControlStateFlag.INSIDE;
            else CurrentState = ControlStateFlag.OUTSIDE;
            DoRighthandControl();
        }
        
        // Perform The control State Operation
        private void DoLefthandControl()
        {
            switch (CurrentState)
            {
                case (ControlStateFlag.INSIDE):
                    OnLeftHandInside(this);
                    break;
                case (ControlStateFlag.OUTSIDE):
                    OnLeftHandOutside(this);
                    break;
            }
        }
        private void DoRighthandControl()
        {
            switch (CurrentState)
            {
                case(ControlStateFlag.INSIDE):
                    OnRightHandInside(this);
                    break;
                case(ControlStateFlag.OUTSIDE):
                    OnRightHandOutside(this);
                    break;
            }
        }

        #endregion

        public virtual void OnRightHandInside(NuiControl control)
        {
            
        }

        public virtual void OnLeftHandInside(NuiControl control)
        {
            
        }

        public virtual void OnLeftHandOutside(NuiControl control)
        {
            
        }

        public virtual void OnRightHandOutside(NuiControl control)
        {
            
        }

        internal void RightHandHitTest(Point point)
        {
            Vector2 vec = new Vector2(point);
           // lefthandmouse.Location = point;
          //  LeftHandHitTest(lefthandmouse);
        }
        /// <summary>
        /// Perform The hit test on all the Window Control
        /// </summary>
        /// <param name="point">The Normalised Hand Screen</param>
        internal void LeftHandHitTest(Point point)
        {
            //righthandmouse.Location = point;
          //  RightHandHitTest(righthandmouse);
        }
    }
    [Flags]
    public enum ControlStateFlag
    {
        INSIDE,
        OUTSIDE
    }
}
